class smx_php {
  require smx_os
  require smx_nginx
  $php_packages_list = [
    'php',
    'php-bcmath',
    'php-devel',
    'php-fpm',
    'php-gd',
    'php-intl',
    'php-xml',
    'php-mcrypt',
    'php-mbstring',
    'php-mysqlnd',
    'php-opcache',#for cpdf collect the os load
    'php-pdo',
    #	 APC causes strange stuff in DEV env, let's disable it for now
    #    The problem has been resolved, now we enable it again
    #	'php-pecl-apc',
    'php-pecl-apcu',
    'php-pecl-mongodb',
    'php-pecl-geoip',
    'php-pecl-redis',
    'php-pecl-xdebug',
    'php-pecl-zip',
  ]
  case $get_server {
    'release-hf.sumilux.com','it-deploy.foxitcloud.com': {
      yumrepo { "remi-php70":
        baseurl    => "http://repo.connectedpdf.com:88/php/remi/enterprise/7/php70/x86_64/",
        mirrorlist => absent,
        descr      => "Remi's PHP 7.0 RPM repository for Enterprise Linux 7 - \$basearch",
        enabled    => 1,
        priority => 1,
        gpgcheck   => 0, }
    }
    'ops30.sumilux.com': {
      yumrepo { "remi-php70":
        baseurl    => "http://repo1.sea.innoscale.net/remi/enterprise/7/php70/x86_64/",
        mirrorlist => absent,
        descr      => "Remi's PHP 7.0 RPM repository for Enterprise Linux 7 - \$basearch",
        enabled    => 1,
        priority => 1,
        gpgcheck   => 0, }
    }
  }

  package { $php_packages_list :
    ensure  => installed,
    before  => Notify['pkg-php-install'],
    require => Yumrepo['remi-php70'],
  }

  notify { 'pkg-php-install':
    message => '----- php7.0 pkgs installation completed -----',
  }

  # use php-pecl-zendopcache replace
  #  case $operatingsystemrelease {
  #    /^6\./: { $apc = "php-pecl-apc" }
  #    /^7\./: { $apc = "php-pecl-apcu" }
  #    default: { fail("Unrecognized operating system for webserver") }
  #  }
  #  package { 'apc':
  #    name => $apc,
  #    ensure => installed,
  #  }
  exec { 'wget_opcache':
    cwd       => '/vagrant/webapp/connectedpdfapp/web',
    command   => "/usr/bin/wget -c https://raw.githubusercontent.com/rlerdorf/opcache-status/master/opcache.php ",
    timeout   => '120', # 2 minites, at most
    logoutput => true,
    creates   => '/vagrant/webapp/connectedpdfapp/web/opcache.php',
    require   => Package['php-opcache'],
  }
  file { '/etc/php.ini':
    ensure  => file,
    group   => root, owner => root, mode => 644,
    source  => 'puppet:///modules/smx_php/php.ini',
    require => Package['php'],
  }

  file { '/etc/php.d/xdebug.ini':
    ensure  => file,
    group   => root, owner => root, mode => 644,
    source  => 'puppet:///modules/smx_php/xdebug.ini',
    require => Package['php'],
  }

  file { '/etc/php-nodebug.ini':
    ensure  => file,
    group   => root, owner => root, mode => 644,
    source  => 'puppet:///modules/smx_php/php-nodebug.ini',
    require => Package['php'],
  }


  file { '/var/lib/php/session/':
    ensure  => present,
    group   => vagrant,
    owner   => vagrant,
    require => Package['php'],
  }

  file { '/vagrant/webapp/runtime':
    ensure => directory,
    #  recurse => true,
    group  => vagrant, owner => vagrant, mode => 777,
  }

  file { '/vagrant/webapp/runtime/swift_mailer_spool':
    ensure  => directory,
    #  recurse => true,
    group   => vagrant, owner => vagrant, mode => 777,
    require => File ['/vagrant/webapp/runtime']
  }

  file { '/mnt/pcslog':
    group  => root, owner => vagrant, mode => 775,
    ensure => directory,
  }

#  file { '/etc/init.d/fxphp':
#    ensure => file,
#    owner  => root, group => root, mode => 755,
#    source => 'puppet:///modules/smx_php/fxphp',
#  }

  file { '/etc/php-fpm.d/www.conf':
    ensure  => file,
    owner   => root, group => root, mode => 644,
    source  => 'puppet:///modules/smx_php/www.conf',
    require => Package['php-fpm'],
  }

#  service { 'fxphp':
#    ensure  => running,
#    enable  => true,
#    path    => "/etc/init.d",
#    start   => "/etc/init.d/fxphp start",
#    stop    => "/etc/init.d/fxphp stop",
#    require => File['/etc/init.d/fxphp'],
#  }

  service { 'php-fpm':
    ensure  => running,
    enable  => true,
    require => Package['php-fpm'],
  }
  case $ipaddress {
    '10.1.103.145' : {
      file { '/etc/foxitcloud/phantom-subscribe-private-key.pem':
        ensure => file,
        group  => root, owner => root, mode => 644,
        source => 'puppet:///modules/smx_php/phantom-subscribe-private-key.pem',
      }
      file { '/etc/foxitcloud/phantom-subscribe-public-key.pem':
        ensure => file,
        group  => root, owner => root, mode => 644,
        source => 'puppet:///modules/smx_php/phantom-subscribe-public-key.pem',
      }
      file { '/etc/foxitcloud/phantom-subscribe-tppk-sign.txt':
        ensure => file,
        group  => root, owner => root, mode => 644,
        source => 'puppet:///modules/smx_php/phantom-subscribe-tppk-sign.txt',
      }
    }
  }

    cron { "send_mail":
      ensure => present,
  	 command => "/vagrant/webapp/yii worker",
  	 user => "vagrant",
  	 minute => "*/1",
  	 hour => "*",
  	 monthday => "*",
      weekday => "*",
       }

}
